package com.system.user.config.akka.actor;

import akka.actor.UntypedAbstractActor;
import com.system.user.entity.TestEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component("TestActor")
@Scope("prototype")
public class TestActor extends UntypedAbstractActor {

    private static final Logger LOGGER = LogManager.getLogger(TestActor.class);

    @Override
    public void onReceive(Object msg) throws Throwable {
        LOGGER.info("TestActor receiver msg", msg.toString());
        if (msg instanceof TestEntity) {
            TestEntity testEntity = (TestEntity) msg;
            int j = 100;
            for (int i = 0; i <= 5; i++) {
                System.out.println(i);
                while (j >= 0) {
                    Thread.sleep(2000);
                    j--;
                    System.out.println(testEntity.getAge() + "-----------" + j);
                }
            }
        }  else {
            unhandled(msg);
        }
        getContext().stop(getSelf());
    }
}
